<template>
  <div :class="className">
    <!-- style -->
    <div v-html="css"></div>

    <!--消费券静态-->
    <div>
      <div id="store" v-if="datas.get_number">
        <div class="nav nav-bgimage" v-if="datas.tab_list && datas.tab_list.length > 0">
          <div class="nav-li nav-selected" v-if="datas.tab_list.indexOf('1') > -1">
            <div class="nav-lis span-ellipsis">
              {{datas.diy_title_1}}
            </div>
          </div>
          <div class="nav-li" v-if="datas.tab_list.indexOf('2') > -1">
            <div class="nav-lis span-ellipsis">
              {{datas.diy_title_2}}
            </div>
          </div>
          <div class="nav-li" v-if="datas.tab_list.indexOf('3') > -1">
            <div class="nav-lis span-ellipsis">
              {{datas.diy_title_3}}
            </div>
          </div>
          <div class="nav-li" v-if="datas.tab_list.indexOf('4') > -1">
            <div class="nav-lis span-ellipsis">
              {{datas.diy_title_4}}
            </div>
          </div>
          <div class="nav-li" v-if="datas.tab_list.indexOf('5') > -1">
            <div class="nav-lis span-ellipsis">
              {{datas.diy_title_5}}
            </div>
          </div>
        </div>
        <div class="store-list">
          <div class="goods-item flex" v-for="(item,index) in 2" :key="index">
            <div class="goods-img">
              <img src="../../../resource/images/image.png" alt="" />
              <div class="flex-j-sb store-name">
                <div v-if="datas.discount_list.indexOf('10') > -1"><span class="iconfont icon-service_n"></span>商户名称</div>
                <div class="units" v-if="datas.discount_list.indexOf('9') > -1">8.88km</div>
              </div>
            </div>
            <div class="goods-name flex-a-c" v-if="datas.discount_list.indexOf('1') > -1">
              <div class="goods-title">
                <span class="dishes">商品名称...</span>
              </div>
            </div>
            <div class="flex packet-red flex-j-sb">
              <div class="consumer-price">
                <span v-if="datas.discount_list.indexOf('2') > -1">¥<span class="number">9</span>
                  <span class="float">.9</span>
                </span>
                <span class="consumer" v-if="datas.discount_list.indexOf('3') > -1">消费券</span>
              </div>
              <div>
                <span class="packet" v-if="datas.discount_list.indexOf('7') > -1||datas.discount_list.indexOf('8') > -1">红包¥9.9</span>
              </div>
              
            </div>
            <div class="flex-j-sb counter-price">
              <div>
                <span class="counter" v-if="datas.discount_list.indexOf('5') > -1">到店付</span>
                <span class="price" v-if="datas.discount_list.indexOf('4') > -1">¥19</span>
              </div>
                <span class="counter-right" v-if="datas.discount_list.indexOf('6') > -1">门市价 <span class="rack-rate">¥24</span></span>
            </div>
            <div class="fine-food flex-j-sb">
              <div class="fine" v-if="datas.discount_list.indexOf('11') > -1">美食</div>
              <div class="number" v-if="datas.discount_list.indexOf('12') > -1">已售496</div>
            </div>
          </div>

        </div>

      </div>
    </div>
  </div>
</template>

<script>
// 自定义样式
const css = function() {
	if (this.datas.preview_color) {
		// 确保数据已传入
		const {
			preview_color,
			font_color,
			money_font_color,
			shop_pay_bg_color,
			shop_pay_font_color,
			shop_pay_money_color,
			tab_bg_color,
			tab_color,
			tab_active_color
		} = this.datas;

		return `
      .component-${this.id} .store-list{
          background-color: ${preview_color};
      }
      .component-${this.id} .store-list .goods-item .consumer-price{
          color: ${money_font_color};
      }
      .component-${this.id} .store-list .goods-item .consumer{
          color: ${font_color};
      }
      .component-${this.id} .store-list .goods-item .counter-price .counter{
          background-color: ${shop_pay_bg_color};
          color: ${shop_pay_font_color};
      }
      .component-${this.id} .store-list .goods-item .counter-price .price{
          color: ${shop_pay_money_color};
      }

      .component-${this.id}  .nav-bgimage{
          background-color: ${tab_bg_color};
          color: ${tab_color};
      }
      .component-${this.id}  .nav-bgimage .nav-selected{
          color: ${tab_active_color};
            border-bottom: 2px solid ${tab_active_color};
      }
    `;
	}
};

export default {
  data() {
    return {};
  },
  props: ["id", "datas", "styles"],
  computed: {
    css() {
      return "<style>" + css.call(this) + "</style>";
    },
    className() {
      const name = ["component-wrapper", `component-${this.id}`];
      return name;
    },
  },

  methods: {
    // rem转换
    px2rem(val = 0) {
      return val / 75 + "rem";
    },
  },

  mounted() {
    this.$emit("loaded");
  },
};
</script>

<style lang="less" scoped>
// 默认
* {
  list-style-type: none;
}
.component-wrapper {
  width: 375px;
}
#store {
  .nav {
    display: flex;
    align-items: center;
    height: 40px;
    white-space: nowrap;
    flex-wrap: nowrap;
    box-sizing: content-box;
    .nav-li {
      flex: 1;
      min-width: 20%;
      text-align: center;
      .nav-lis {
        width: 100%;
        display: block;
        line-height: 40px;
      }
    }
  }
  .store-list {
    display: flex;
    justify-content: space-evenly;
    width: 100%;
    overflow: hidden;
    padding: 10px 0;
   .goods-item {
      width: 170px;
      background-color: #ffffff;
      border-radius: 15px;
      overflow: hidden;
      flex-direction: column;
      padding: 0 0 5px 0;
      margin-bottom: 5px;
    }
    .goods-item .goods-img {
      width: 170px;
      height: 170px;
      border-radius: 8px 8px 0 0;
      position: relative;
    }
    .goods-item .goods-img img{
      display: block;
      width: 100%;
      height: 100%;
    }
    .goods-img .label {
      position: absolute;
      left:0;
      top:0;
      z-index: 99;
      font-size: 12px;
      color: #ffffff;
      background: linear-gradient(90deg, #FF6A3F 0%, #FF3B01 100%);
      padding: 0 3px;
      border-radius: 8px 0 8px 0;
    }
    .goods-img  .store-name {
      width: 100%;
      height: 26px;
      position: absolute;
      left:0;
      bottom:0;
      z-index: 5;
      background-color: rgba(0, 0, 0, 0.5);
      align-items: center;
      font-size: 12px;
      color: #fff;
    }
    .store-name .icon-service_n {
      color: #fff;
      font-size: 12px;
    }
    .store-name .units {
      margin-right: 4px;
    }
    .goods-name {
      margin: 8px 10px;
    }
    .goods-name .store-label {
      font-size: 5px;
      color: #ffffff;
      padding: 4px 5px;
      border-radius: 5px;

    }
    .goods-name  .goods-title {
      font-size: 13px;
      color: #35314a;
    }
    .goods-name  .dishes {
      line-height: 25px;
      font-size: 13px;
      color: #35314a;
    }
    .blue {
      background-color: #2aa2ff;
    }

    /*消费红包*/
    .packet-red {
      margin: 0 8px;
      align-items: center;
      /* justify-content: flex-end; */
    }
    .packet {
      text-align: center;
      display: inline;
      font-size: 5px;
      color: #ff3a00;
      border: 1px solid #ff3a00;
      padding: 3px 4px 3px 4px;
      border-radius: 3px;
    }
    /*消费券*/ 
    .consumer-price {
      font-size: 12px;
    }
    .consumer-price .float {
      font-size: 12px;
    }
    .consumer-price .number {
      font-size: 18px;
    }
    .consumer-price .consumer {
      font-size: 5px;
      margin-left: 3px;
    }


    .unit-price {
      font-size: 12px;
      color: #ff3a00;
    }
    .orange {
      background-color: #ff2c00;
    }
    .goods-sold {
      margin: 0 18px 0 7px;
      align-items: flex-end;
    }
    .unit-price .number {
      font-size: 20px;
    }
    .unit-price .number {
      font-size: 27px;
    }
    .sold-out {
      font-size: 5px;
      color: #b5b5b5;
      margin-bottom: 8px;
    }
    /*到店付*/
    .counter-price {
      margin: 12px 8px;
      align-items: center;
    }
    .counter {
      font-size: 5px;
      padding: 3px 4px 3px 3px;
      border-radius: 3px;
    }
    .counter-price .price {
      font-size: 15px;
      margin-left: 5px;
    }
    .counter-price .counter-right {
      color: #686868;
      font-size: 12px;
    }
    .rack-rate {
      font-size: 12px;
      text-decoration-line:line-through;
    }
    .fine-food {
      margin: 0px 8px 8px 8px;
    }
    .fine {
      font-size: 5px;
      color: #9aa4bf;
      padding: 3px 5px 3px 5px;
      background-color: #f2f6f9;
    }
    .fine-food .number {
      font-size: 5px;
      color: #b5b5b5;
    }
  }

  .span-ellipsis {
    overflow: hidden; /*超出部分隐藏*/
    text-overflow: ellipsis; /* 超出部分显示省略号 */
    white-space: nowrap; /*规定段落中的文本不进行换行 */
  }
  .line {
    width: 1px;
    height: 50%;
    background: #bbbbbb;
    margin: 0 5px;
  }
  .scroll {
    overflow-x: scroll;
  }
}
</style>
